{% extends 'base.html' %}

{% block content %}
<h4>{{ object|yesno:'更新作业,创建作业' }}</h4>
<form method="post">
    {% csrf_token %}
    {% load widget_tweaks %}
    {% if form.errors %}
    <div class="alert alert-danger">
        <strong>表单提交失败，请检查以下错误：</strong>
        <ul>
            {% for field in form %}
                {% for error in field.errors %}
                    <li>{{ field.label }}: {{ error }}</li>
                {% endfor %}
            {% endfor %}
            {% for error in form.non_field_errors %}
                <li>{{ error }}</li>
            {% endfor %}
        </ul>
    </div>
    {% endif %}
    {% for field in form %}
    <div class="mb-3">
        {{ field.label_tag }}
        {% if field.name in 'assigned_date,due_date' %}{% render_field field class="form-control" type="date" %}{% else %}{% render_field field class="form-control" %}{% endif %}
        {% for error in field.errors %}
            <div class="invalid-feedback d-block">{{ error }}</div>
        {% endfor %}
    </div>
    {% endfor %}
    <button type="submit" class="btn btn-primary">保存</button>
    <a href="{% url 'core:homework_list' %}" class="btn btn-secondary">取消</a>
</form>
{% endblock %}